<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="renderer" content="webkit">
    <link rel="stylesheet" href="mdui/css/mdui.min.css">
    <script defer src="mdui/js/mdui.min.js"></script>
    <script src="js/axios.min.js"></script>
    <script src="js/qs.min.js"></script>
    <script src="js/common.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            height: 100%;
            height: 100%;
            color: #61dafb;
        }

        .login {
            width: 358px;
            height: 588px;
            border-radius: 15px;
            padding: 0 50px;
            position: relative;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            background-color: #282c34;
        }

        .header {
            font-size: 26px;
            font-weight: bold;
            text-align: center;
            line-height: 200px;
            color: #61dafb;
        }

        .container {
            height: 30px;
            width: 250px;
            position: absolute;
            left: 50%;
            top: 35%;
            transform: translate(-50%, -50%);
        }

        input {
            width: 100%;
            height: 100%;
            position: relative;
            outline: none;
            border: none;
            box-sizing: border-box;
            padding-left: 5px;
            background-color: #282c34;
            color: #61dafb;
            caret-color: #61dafb;
        }

        input::placeholder {
            color: #61dafb;
        }

        span {
            position: absolute;
            content: "";
            display: block;
            background-color: #61dafb;
            transition: transform 0.1s ease-in-out;
        }

        .top,
        .bottom {
            left: 0px;
            right: 0px;
            height: 2px;
        }

        .left,
        .right {
            top: 0px;
            bottom: 0px;
            width: 2px;
            transform: scaleY(0);
        }

        .top {
            top: 0px;
            transform: scaleX(0);
            transform-origin: left center;
            transition-delay: 0.2s;
        }

        .left {
            left: 0px;
            transform-origin: bottom center;
            transition-delay: 0.3s;
        }

        .bottom {
            bottom: 0px;
        }

        .right {
            right: 0px;
            transform-origin: top center;
            transition-delay: 0.1s;
        }

        input:focus ~ .right {
            transform: scaleY(1);
            transform-origin: bottom center;
        }

        input:focus ~ .left {
            transform: scaleY(1);
            transform-origin: top center;
        }

        input:focus ~ .top {
            transform: scaleY(1);
            transform-origin: right center;
        }

        .container1 {
            height: 30px;
            width: 250px;
            position: absolute;
            left: 50%;
            top: 45%;
            transform: translate(-50%, -50%);
        }

        .container2 {
            height: 30px;
            width: 250px;
            position: absolute;
            right: -25px;
            top: 310px;
            line-height: 30px;
            transform: translate(-50%, -50%);
        }

        .btn {
            position: absolute;
            left: 50%;
            top: 54%;
            transform: translate(-50%, -50%);
            text-align: center;
            padding: 5px;
            width: 52%;
            margin-top: 40px;
            background-color: #61dafb;
            color: #fff;
        }

        .container2 ul li {
            float: left;
            list-style: none;
            margin-left: 20px;
        }

        .admin, .student {
            display: block;
            margin-right: 4px;
            margin-top: 7px;
            float: left;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: #ffffff;
        }

        .resgist {
            height: 30px;
            width: 250px;
            position: absolute;
            right: -190px;
            top: 405px;
            line-height: 30px;
            transform: translate(-50%, -50%);
        }

        a {
            color: #61dafb;
            text-decoration: none;
        }

        .souye {
            position: absolute;
            top: 10px;
            right: 50px;
        }

    </style>
</head>
<body>

<div class="login">
    <a href="index.html" class="souye">首页</a>
    <div class="header">校园维修管理系统登录</div>
    <div class="container">
        <input type="text" placeholder="请输入用户名" id="loginName"/>
        <span class="left"></span>
        <span class="right"></span>
        <span class="top"></span>
        <span class="bottom"></span>
    </div>
    <div class="container1">
        <input type="password" placeholder="请输入密码" id="pwd"/>
        <span class="left"></span>
        <span class="right"></span>
        <span class="top"></span>
        <span class="bottom"></span>
    </div>
    <div class="container2">
        <ul>
            <li>角色:</li>
            <li><i class="admin "></i>管理员</li>
            <li><i class="student "></i>用户</li>
        </ul>
    </div>
    <div class="login-admin btn" onclick="doLogin1()">管登录</div>
    <div class="login-student btn" onclick="doLogin2()">用登录</div>
    <div class="resgist"><a href="regist.html">没有账号？进行注册</a></div>
</div>

<script>

    var admin = document.querySelector('.admin');
    var student = document.querySelector('.student');
    let login_admin = document.querySelector('.login-admin');
    let login_student = document.querySelector('.login-student');
    console.log(login_student);
    console.log(admin);

    admin.onclick = function () {
        console.log(123)
        this.style.backgroundColor = '#61dafb'
        student.style.backgroundColor = '#ffffff'
        login_admin.style.display = ' block'
        login_student.style.display = 'none'
    }
    student.onclick = function () {
        this.style.backgroundColor = '#61dafb'
        admin.style.backgroundColor = '#ffffff'
        login_admin.style.display = 'none '
        login_student.style.display = 'block'
    }
    console.log(student);

    //管理员登录
    function doLogin1() {
        console.log(123)
        let loginid = document.getElementById('loginName').value;
        console.log(loginid)
        let pwd = document.getElementById('pwd').value;

        if (loginid == '' || pwd == "") {

            mdui.alert("请输入用户和密码")
            return
        }
        let _this = this;
        axios.post("/admin/checklogin",
            Qs.stringify({
                "loginid": loginid,
                "pwd": pwd
            })
        ).then(function (res) {
            if (res.data.success) {
                sessionStorage.setItem("userId", res.data.userId);//sessionStorage针对当前用户有效关闭浏览器就失效
                // sessionStorage.setItem("roleId", res.data.roleId);
                mdui.alert("登录成功")
                location.href = "AdminIndex.html"
            } else {
                mdui.alert("登录失败" + res.data.msg)
            }
        })
    }

    //学生登录
    function doLogin2() {
        let loginid = document.getElementById('loginName').value
        let pwd = document.getElementById('pwd').value;
        if (loginid == '' || pwd == "") {
            mdui.alert("请输入用户和密码")
            return
        }
        let _this = this;
        axios.post("/student/checklogin",
            Qs.stringify({
                "loginid": loginid,
                "pwd": pwd
            })
        ).then(function (res) {
            if (res.data.success) {
                sessionStorage.setItem("id", res.data.userId);//sessionStorage针对当前用户有效关闭浏览器就失效
                // sessionStorage.setItem("roleId", res.data.roleId);
                mdui.alert("登录成功")
                location.href = "StudentIndex.html"
            } else {
                mdui.alert("登录失败" + res.data.msg)
            }
        })
    }
</script>
</body>
</html>